package com.filmbooks.model;

import com.filmbooks.api.DoubanApi;
import com.filmbooks.contract.detail.MovieDeatilContract;
import com.filmbooks.model.home.bean.movie.MovieDetailBean;
import com.filmbooks.model.home.bean.movie.PersonBean;
import com.zyw.horrarndoo.sdk.base.BaseModel;
import com.zyw.horrarndoo.sdk.helper.RetrofitCreateHelper;
import com.zyw.horrarndoo.sdk.helper.RxHelper;

import io.reactivex.Observable;
import io.reactivex.functions.Function;

/**
 * Created by heshuxiang on 2018/3/9.
 * 描述：
 * 公司：盟将威
 * 作者：heshuxiang
 * 日期：2018/3/9.
 * 工程：FilmBooks
 * 包：com.filmbooks.model
 */

public class MovieDetailModel extends BaseModel implements MovieDeatilContract.IMovieDetailModel {
    @Override
    public Observable<MovieDetailBean> getMovieDetail(String id) {
        return RetrofitCreateHelper.createApi(DoubanApi.class, DoubanApi.HOST).getMovieDetail(id).compose(RxHelper.<MovieDetailBean>rxSchedulerHelper()).map(new Function<MovieDetailBean, MovieDetailBean>() {
            @Override
            public MovieDetailBean apply(MovieDetailBean bean) throws Exception {
                //返回的数据没有person type，根据数组类型指定
                for (PersonBean bean1 : bean.getCasts()) {
                    bean1.setType("主演");
                }
                for (PersonBean bean2 : bean.getDirectors()) {
                    bean2.setType("导演");
                }
                return bean;
            }
        });
    }

    public static MovieDeatilContract.IMovieDetailModel newInstance() {
        return new MovieDetailModel();
    }
}
